package gs.android.einsteinballoons;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ProgressBar;

public class LoadingActivity extends Activity {
	private ProgressBar bar;
	private int progressStatus = 0;
	
	private Handler handler = new Handler();
	
	@Override
	public void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);
		setContentView(R.layout.loading);
		
		bar = (ProgressBar) findViewById(R.id.bar);
		new Thread(new Runnable() {
			@Override
			public void run() {
				while (progressStatus < 100) {
                    progressStatus += task();
                    
                    try {
						Thread.sleep(30);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
                    
                    handler.post(new Runnable() {
                        public void run() {
                            bar.setProgress(progressStatus);
                        }
                    });
                }
				
				if (progressStatus >= 100) {
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				
				Intent intent = new Intent(getApplicationContext(), MainActivity.class);
				startActivity(intent);
				finish();
			}
		}).start();
	}
	
	public int task() {
		return 1;
	}
}
